/*
 * Copyright 2010,2011,2012 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.schnipsel.zentral;

import de.mnit.basis.daten.struktur.liste.Liste;
import de.mnit.basis.daten.struktur.liste.S_Liste;
import de.mnit.basis.swt.vorlage.A_Zurueck;

/**
 * @author Michael Nitsche
 * 17.07.2010	Erstellt
 *
 * TODO Hier könnte man auch den Baum speichern
 */
public class SC_Zurueck extends A_Zurueck<B_Zurueck> {

	private static final int MAX=30;
	private static SC_Zurueck instanz=null;
	private S_Liste<B_Zurueck> zurueck;


	public static SC_Zurueck i() {
		if(instanz==null)
			instanz=new SC_Zurueck();
		return instanz;
	}

	public SC_Zurueck() {
		super();

		// Geplant
//		this.eKomplettZurueck(new S_Zuhoerer<Object>() {
//			public void verarbeite(Object o) {
//				Ausgabe.debug();
//				SC_GuiObs.i().anzeige().sGeaendert(false);
//			}
//		});
	}

	protected void pNeu() {
		this.zurueck=Liste.neu();
	}

	protected void pMinusLetzten() {
		zurueck.minusLetzten();
	}

	protected boolean pPlus() {
		Integer id =SC_GuiObs.i().anzeige().gID();
		Integer pos=SC_GuiObs.i().anzeige().gPosition();
		if(id!=null)
			if(this.zurueck.gLaenge()==0 || (this.zurueck.gLaenge()>0 && !this.zurueck.gibLetzten().equals(id))) {
				this.zurueck.plus(new B_Zurueck(id,pos));
				return true;
			}
		return false;
	}

	protected void pSetze(int pos) {
		B_Zurueck bz=this.zurueck.gib(pos);
		SC_Events.zeigArtikel(bz.id, true, null, bz.pos);
	}

	protected int pLaenge() {
		return this.zurueck.gLaenge();
	}

	protected int pMax() {
		return MAX;
	}

	protected void pMinusErsten() {
		this.zurueck.minus(1);
	}
}
